package cn.iocoder.boot.controller.admin;
import cn.iocoder.boot.dto.SuppliersQueryTO;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.iocoder.boot.service.IComponentSupplierService;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.boot.entity.ComponentSupplier;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/componentSupplier")
@Tag(name = "元器件 - 供应商管理")
public class ComponentSupplierController {

    @Autowired
    private IComponentSupplierService componentSupplierService;

    @PostMapping("/save")
    @Operation(summary = "创建供应商")
    public CommonResult<Boolean> saveComponentSupplier(@RequestBody ComponentSupplier componentSupplier) {
        return CommonResult.success(componentSupplierService.saveComponentSupplier(componentSupplier));
    }

    @PostMapping("/update")
    @Operation(summary = "更新供应商")
    public CommonResult<Boolean> updateComponentSupplier(@RequestBody ComponentSupplier componentSupplier) {
        return CommonResult.success(componentSupplierService.updateComponentSupplier(componentSupplier));
    }

    @PostMapping("/delete/{id}")
    @Operation(summary = "删除供应商")
    public CommonResult<Boolean> deleteComponentSupplier(@PathVariable Long id) {
        return CommonResult.success(componentSupplierService.deleteComponentSupplier(id));
    }

    @GetMapping("/get/{id}")
    @Operation(summary = "供应商详情")
    public CommonResult<ComponentSupplier> getComponentSupplier(@PathVariable Long id) {
        return CommonResult.success(componentSupplierService.getComponentSupplier(id));
    }



    @PostMapping("/list")
    @Operation(summary = "供应商分页")
    public CommonResult<Page<ComponentSupplier>> listComponentSuppliers(@RequestBody SuppliersQueryTO to) {
        // 创建 Lambda 查询条件的包装器


        return CommonResult.success(componentSupplierService.listComponentSuppliers(to));
    }

    @PostMapping("/getList")
    @Operation(summary = "供应商列表")
    public CommonResult<List<ComponentSupplier>> getList() {
        // 创建 Lambda 查询条件的包装器


        return CommonResult.success(componentSupplierService.getList());
    }


}
